$(function() {	
	$('#huodg4').datagrid({
		//请求地址
	    url:'../check/getholidaykind',
	    columns:[[
	    	{field:'',title:'',checkbox:true},
			{field:'holidayId',title:'假种编号',width:'8%'},
			{field:'holidayName',title:'假种名称',width:'8%'},
			{field:'whetherSalary',title:'薪资处理',width:'8%',
				formatter : function(value, row, index) {
					if (row.whetherSalary ==='带薪') {
						return '带薪';
					} else if (row.personageHoliday === '不带薪') { 
						return '不带薪';
					}
				}	
			},
			{field:'personageHoliday',title:'个人假种',width:'8%',disabled:true,
				formatter : function(value, row, index) {
					if (row.personageHoliday === "true") {
						var btn1 = " <input type='checkbox' checked='checked'>";
						return btn1;
					} else if (row.personageHoliday === "false") {
					    var btn2 = " <input type='checkbox' >";
						return btn2;
					}
				}
			},
			{field:'statutoryHoliday',title:'法定假种',width:'8%',disabled:true,
				formatter : function(value, row, index) {
					if (row.statutoryHoliday === 'true') {
						var btn3 = " <input type='checkbox' checked='checked'>";
						return btn3;
					} else if (row.statutoryHoliday === 'false') {
						var btn4 = " <input type='checkbox'>";
						return btn4;
					} 
				}
			},
			{field:'remark',title:'备注',width:'15%'},
			{field:'systemUse',title:'系统应用',width:'8%',disabled:true,
				formatter : function(value, row, index) {
					if (row.systemUse == 'true') {
						var btn5 = " <input type='checkbox' checked=true>";
						return btn5;
					} else if (row.systemUse == 'false') {
						var btn6 = " <input type='checkbox'>";
						return btn6;
					}
				}
			},
			{field:'maker',title:'创建者',width:'8%'},
			{field:'makeTime',title:'创建日期',width:'15%'},
			{field:'updateEmp',title:'修改者',width:'8%'},
			{field:'updateTime',title:'修改日期',width:'15%'},
			{field:'state',title:'状态',width:'4%',
				formatter : function(value, row, index) {
					if (row.state) {
					var btns = "<a id='huoUpdate' name='opera4'  class='easyui-linkbutton'></a>";
					return btns;
					}
				}
			} ] ],
		onLoadSuccess : function(data) {
			$("a[name='opera4']").linkbutton({
				plain : true,
				iconCls : 'icon-edit'
			});
			$("a[name='opera4']").bind('click',function(){
				var rows = $('#huodg4').datagrid('getSelected');
				$("#holidayId").val(rows.holidayId);
				$("#holidayName").val(rows.holidayName);
				$("#remark").val(rows.remark);
				$("#personageHoliday").attr("checked",rows.personageHoliday);
				$("#statutoryHoliday").attr("checked",rows.statutoryHoliday);
				$("#systemUse").attr("checked",rows.systemUse);
				$("#maker").val(rows.maker);
				$("#makeTime").val(rows.makeTime);
				$("#huodd4").window("open");
			})
		},
		onLoadError:function(data){
			alert("加载失败")
		},
	    width:'100%',
	    fit:true,
	    //fit:true
	    fitColumns:true,
	    //隔行变色
	    striped:true,
	    nowrap:true,
	    //显示行号
	    rownumbers:true,
	    //设置单选
	    singleSelect:true,
		toolbar:'#huotb4',
		//显示分页栏
		pagination:true,
		//设置每页大小
		pageSize:5,
		//可选的每页大小
		pageList:[5,10,20,50]
	});
});
 function searchname(value){
	 $('#huodg4').datagrid('load','../check/serchHolidayKind?serch_jsondata='+value);
} 
 
 
    var editIndex = undefined;
	function endEditing(){
		if (editIndex == undefined){return true}
		if ($('#huodg4').datagrid('validateRow', editIndex)){
			$('#huodg4').datagrid('endEdit', editIndex);
			editIndex = undefined;
			return true;
		} else {
			return false;
		}
	}
	function onClickCell(index, field){
		if (editIndex != index){
			if (endEditing()){
				$('#huodg4').datagrid('selectRow', index)
						.datagrid('beginEdit', index);
				var ed = $('#huodg4').datagrid('getEditor', {index:index,field:field});
				if (ed){
					($(ed.target).data('textbox') ? $(ed.target).textbox('textbox') : $(ed.target)).focus();
				}
				editIndex = index;
			} else {
				setTimeout(function(){
					$('#huodg4').datagrid('selectRow', editIndex);
				},0);
			}
		}
	}
	function onEndEdit(index, row){
		var ed = $(this).datagrid('getEditor', {
			index: index,
			field: 'dname'
		});
		row.dname = $(ed.target).combobox('getText');
	}
	function removeit(){
		if (editIndex == undefined){
			var rows = $('#huodg4').datagrid('getSelections');
			if(rows.length > 0){
				$.messager.confirm('请确认','您确定要删除当前所有选中的项目吗？',function(r){
					if(r){
						var holidayIds = [];
						for(var i = 0; i < rows.length; i++){
							holidayIds.push(rows[i].holidayId)
						}
						var huo_rowData = JSON.stringify(holidayIds);
						alert(huo_rowData);
						$.ajax({
							url : "../check/deleteHolidayKind",
							data : {"huo_rowData" : huo_rowData},
							success : function(e) {
								if (e == "ok") {
	                               alert("删除成功");
	                               $('#huodg4').datagrid('load');
								}
							}
						});
					}
				 })
				}
		}
		$('#huodg4').datagrid('cancelEdit', editIndex).datagrid('deleteRow', editIndex);
		editIndex = undefined;
	}